package user

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"project-im/config"
	"project-im/internal/api/request"
	"project-im/internal/model/dao"
)

func UserInfo(c *gin.Context) {
	var json request.InfoUpdate
	if err := c.ShouldBindJSON(&json); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	values, _ := c.Get("userId")
	var user dao.ImUser
	config.DB.Where("id=?", values).Limit(1).Find(&user)
	imUser := dao.ImUser{
		ID:             user.ID,
		NickName:       json.NickName,
		HeadImage:      json.HeadImage,
		HeadImageThumb: json.HeadImageThumb,
		Sex:            json.Sex,
		SigNature:      json.SigNature,
	}
	config.DB.Model(&user).Updates(&imUser)
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "修改成功",
		"data": nil,
	})
}
